<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 86158
  Date: 2022/2/26
  Time: 22:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>CoolMeeting会议管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/styles/common.css"/>
    <script src="${pageContext.request.contextPath}/js/jquery-3.6.0.js"></script>
    <script type="text/javascript">
        var depname;//部门名称的值
        function cancelDep(depid){
            var editBtn=$('#edit'+depid);
            var cancelBtn=$('#cancel'+depid);
            var ele=$('#depname'+depid);
            cancelBtn.css('display','none');
            editBtn.html('编辑');
            ele.html(depname);
        }
        function editDep(depid){
            var editBtn=$('#edit'+depid);
            var cancelBtn=$('#cancel'+depid);
            var ele=$('#depname'+depid);
            depname=ele.html();//每次点编辑时保存部门名称的值
            if(cancelBtn.css('display')=='none'){//取消
                cancelBtn.css('display','inline');
                editBtn.html('确定');
                var depName=ele.text();
                ele.html('<input type="text" value="'+depName+'"/>')
            }else{//确定
                var children=ele.children('input');
                var val=children.val();
                $.post('/admin/updateDep',{id:depid,name:val},function (msg){
                    if(msg=='success'){
                        cancelBtn.css('display','none');
                        editBtn.html('编辑');
                        ele.html(val);
                    }
                })
            }
        }
    </script>
</head>
<body>
<div class="page-header">
    <div class="header-banner">
        <img src="${pageContext.request.contextPath}/images/header.png" alt="CoolMeeting"/>
    </div>
    <div class="header-title">
        欢迎访问Cool-Meeting会议管理系统
    </div>
    <div class="header-quicklink">
        欢迎您，<strong>${sessionScope.currentuser.employeename}</strong>
        <a href="${pageContext.request.contextPath}/changepassword">[修改密码]</a>
    </div>
</div>
<div class="page-body">
    <div class="page-sidebar">
        <div class="sidebar-menugroup">
            <jsp:include page="leftMenu.jsp" flush="true"></jsp:include>
        </div>
    </div>
    <div class="page-content">
        <div class="content-nav">
            人员管理 > 部门管理
        </div>
        <form action="${pageContext.request.contextPath}/admin/addDepartment" method="post">
            <fieldset>
                <legend>添加部门</legend>
                部门名称:
                <input type="text" name="departmentname" id="departmentname" maxlength="20"/>
                <input type="submit" class="clickbutton" value="添加"/>
                <div style="color: red">${error}</div>
            </fieldset>
        </form>
        <table class="listtable">
            <caption>所有部门:</caption>
            <tr class="listheader">
                <th>部门编号</th>
                <th>部门名称</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${deps}" var="dep">
                <tr>
                    <td>${dep.departmentid}</td>
                    <td id="depname${dep.departmentid}">${dep.departmentname}</td>
                    <td>
                        <a class="clickbutton" href="#" id="edit${dep.departmentid}" onclick="editDep(${dep.departmentid})">编辑</a>
                        <a class="clickbutton" style="display: none" href="#" id="cancel${dep.departmentid}" onclick="cancelDep(${dep.departmentid})">取消</a>
                        <a class="clickbutton" href="/admin/deleteDep/${dep.departmentid}">删除</a>
                    </td>
                </tr>
            </c:forEach>

        </table>
    </div>
</div>
<div class="page-footer">
    <hr/>
    更多问题，欢迎联系<a href="mailto:webmaster@eeg.com">管理员</a>
    <img src="${pageContext.request.contextPath}/images/footer.png" alt="CoolMeeting"/>
</div>
</body>
</html>